package com.kehutong.question.admin;

import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.jdbc.JdbcSession;

import com.kehutong.common.util.Token;
import com.kehutong.question.entity.QuestionCommonClassify;
import com.kehutong.question.service.QuestionClassifyService;

/**
 * 管理后台-消息管理-分类管理
 */
@MvcAction
@ReqMapping("/admin/crm/question/classify")
public class ClassifyController {

    @Inject
    private QuestionClassifyService classifyService;
    @Inject
    private JdbcSession jdbcSession;

    @HasPermission("crm:question:common:classify:view")
    @ReqMapping("/list/page")
    public Object listPage(JSONObject jsonObject) {
        return classifyService.listPage(jsonObject);
    }

    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {
        return classifyService.list(jsonObject);
    }

    @HasPermission("crm:question:common:classify:add")
    @Bean(newInstance=true, copy=true)
    @ReqMapping("/save")
    public Object save(QuestionCommonClassify classify, Token token) {
        classify.setCreateUserId(token.getUuid());
        classify.setCreateUserName(token.getUsername());

        return classifyService.save(classify);
    }

    @HasPermission("crm:question:common:classify:edit")
    @Bean(copy=true)
    @ReqMapping("/update")
    public Object update(QuestionCommonClassify classify) {

        return classifyService.update(classify);
    }

    @HasPermission("crm:question:common:classify:del")
    @ReqMapping("/delete")
    public Object delete(QuestionCommonClassify classify) {

        return classifyService.delete(classify);
    }

    @HasPermission("crm:question:common:classify:edit")
    @Bean(copy = true)
    @ReqMapping("/updateSort")
    public Object updateSort(QuestionCommonClassify classify, Integer sort) {

        return classifyService.updateSort(classify, sort);
    }

    @ReqMapping("/get")
    public Object get(QuestionCommonClassify classify) {

        return Result.success(classify);
    }
}
